import api from './api';

// 课程相关API服务

// 获取学生加入的课程列表
export const getStudentCourses = () => {
  return api.get('/student/course/list');
};

// 学生加入课程
export const joinCourse = (courseId) => {
  return api.post('/student/course/join', {
    course_id: courseId
  });
};

// 签到相关API服务

// 获取待签到任务列表
export const getPendingSignInTasks = () => {
  return api.get('/student/sign_in/tasks');
};

// 学生执行签到
export const doSignIn = (taskId, faceImage, location = null) => {
  const data = {
    sign_in_task_id: taskId,
    face_image: faceImage
  };
  
  // 如果有位置信息，添加到请求数据
  if (location) {
    if (typeof location === 'string') {
      data.location = location;
    } else if (typeof location === 'object') {
      data.latitude = location.latitude;
      data.longitude = location.longitude;
      data.accuracy = location.accuracy;
      data.location = `纬度: ${location.latitude}, 经度: ${location.longitude}`;
    }
  }
  
  return api.post('/student/sign_in', data);
};

// 获取签到历史记录
export const getSignInHistory = () => {
  return api.get('/student/sign_in/history');
};

// 更新学生人脸信息
export const updateFaceInfo = (faceImage) => {
  return api.post('/student/face', {
    face_image: faceImage
  });
};

// 获取用户信息
export const getStudentInfo = () => {
  return api.get('/student/info');
}; 